package com.woniuxy.microcontentserver.sectionmsg.mapper;

import com.woniuxy.microcontentserver.bean.SectionBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SectionMapper {
    /**
     * 查询所有栏目
     * @param
     * @param sectionBean
     * @return
     */
    List<SectionBean> findAll(@Param("s") SectionBean sectionBean);

    /**
     * 根据id查询栏目
     * @param id
     * @return
     */
    @Results({
            @Result(id=true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "name",column = "name",javaType = String.class),
            @Result(property = "sequence",column = "sequence",javaType = Integer.class),
            @Result(property = "describe",column = "describe",javaType = String.class),
            @Result(property = "status",column = "status",javaType = Integer.class),
    })
    @Select("select * from section_info where id=#{id}")
    SectionBean getOneById(Long id);

    /**
     * 新增栏目
     * @param sectionBean
     * @return 受影响的行数
     */
    @Options(
            useGeneratedKeys = true,
            keyProperty = "s.id"
    )
    @Insert("insert into section_info"+
            "(name,sequence,describe,status)"+
            "values(#{s.name},#{s.sequence},#{s.describe},#{s.status})"
            )
    int addSectionBean(@Param("s") SectionBean sectionBean);

    /**
     * 修改栏目
     * @param sectionBean
     * @return 受影响的行数
     */
    @Update("<script>"+
            "update section_info"+
            "<set>"+

            "<if test='s.name != null'>" +
            " name = #{s.name}," +
            "</if>" +

            "<if test='s.sequence != null'>" +
            " sequence = #{s.sequence}," +
            "</if>" +

            "<if test='s.describe != null'>" +
            " describe = #{s.describe}," +
            "</if>" +

            "<if test='s.status != null'>" +
            " status = #{s.status}," +
            "</if>" +

            "</set>"+
            "where id=#{s.id}"+
            "</script>"
         )
    int updateSectionBean(@Param("s") SectionBean sectionBean);

    /**
     * 删除栏目
     * @param id
     * @return 受影响的行数
     */
    @Delete("delete from section_info where id=#{id}")
    int deleteSectoinBean(@Param("id") Long id);


}
